<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>后台</title>
    <link href="./css/default.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="./themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="./themes/icon.css" />
    <script type="text/javascript" src="./js/jquery-1.6.2.min.js"></script>
	<script type="text/javascript" src="./js/jquery.easyui.min.js"></script>
	<?php
		if ($_REQUEST['lang'] == 'sc'){
			echo "<script type='text/javascript' src='./js/locale/easyui-lang-zh_CN.js'></script>";
		}else if ($_REQUEST['lang'] == 'tc'){
			echo "<script type='text/javascript' src='./js/locale/easyui-lang-zh_TW.js'></script>";
		}else{
			echo "<script type='text/javascript' src='./js/locale/easyui-lang-zh_CN.js'></script>";
		}
	?>
	<script type="text/javascript">
		$(document).ready(function(){
		$('#list').datagrid({  
			url:'/interface.php',
			queryParams:{lang:'<?php echo $_REQUEST['lang'];?>',type:'img',action:'list'},
			fitColumns: true,
			striped: true,
			nowrap: true,
			pagination: true,
			rownumbers: true,
			remoteSort: false,
			idField:'id',
			columns:[[
				{field:'id',hidden:true},  
				{field:'title',title:'标题',width:100,sortable:true,resizable:true},  
				{field:'url',title:'链接',width:100,sortable:true,resizable:true},  
				{field:'src',title:'图片',width:100,resizable:true,
					formatter:function(value,row,index){
						var e = '<img width="340" height="92" src="<?php echo (($_REQUEST['lang'] == 'sc')?"../upload/index_img/sc/big/":"../upload/index_img/tc/big/");?>'+value+'" />';
						return e;
					}
				},
				{field:'queue',title:'顺序',width:100,resizable:true,sortable:true,editor:'numberbox'},
				{field:'action',title:'操作',width:80,align:'center',
					formatter:function(value,row,index){
						if (row.editing){
							var s = '<a href="#" onclick="savequeue('+index+')">保存</a> ';
							var c = '<a href="#" onclick="cancelrow('+index+')">取消</a>';
							return s+c;
						}else{
							var e = '<a href="#" onclick="editrow('+row.id+',\''+row.title+'\')">修改</a> ';
							var d = '<a href="#" onclick="deleterow('+row.id+')">删除</a>';
							return e+d;
						}
						
					}
				}
			]],
			onBeforeEdit:function(index,row){
				row.editing = true;
				updategrid();
			},
			onDblClickRow:function(index,row){
				$('#list').datagrid('beginEdit', index);
			},
			onCancelEdit:function(index,row){
				row.editing = false;
				updategrid();
			},
			onAfterEdit:function(index,row){
				$.ajax({
				  url: "/interface.php",
				  async: true,
				  type:'POST',
				  dataType:'json',
				  data:{type:'img',id:row.id,queue:row.queue,action:'editqueue'},
				  success: function(msg){
					if (msg == 'success'){
						$.messager.alert('成功','修改成功');
						row.editing = false;
						updategrid();
					}
				  }
				});
			}
		});
	});
	function addTab(subtitle,url){
		if(!window.parent.$('#tabs').tabs('exists',subtitle)){
			window.parent.$('#tabs').tabs('add',{
				title:subtitle,
				content:createFrame(url),
				closable:true,
				icon:'icon-edit'
			});
		}else{
			window.parent.$('#tabs').tabs('select',subtitle);
		}
	}
	
	function createFrame(url)
	{
		var s = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
		return s;
	}
	
	function updategrid(){
		var rowcount = $('#list').datagrid('getRows').length;
		for(var i=0; i<rowcount; i++){
			$('#list').datagrid('updateRow',{
				index:i,
				row:{action:''}
			});
		}
	}
	function editrow(id,title){
		<?php
			if ($_REQUEST['lang'] == 'sc'){
				echo "addTab(title,'/admin/uploadimg.php?lang=sc&action=edit&id='+id);";
			}else if ($_REQUEST['lang'] == 'tc'){
				echo "addTab(title,'/admin/uploadimg.php?lang=tc&action=edit&id='+id);";
			}
		?>	
	}
	function savequeue(index){
		$('#list').datagrid('endEdit', index);
	}
	function deleterow(id){
		$.messager.confirm('确认','确定删除吗?',function(r){
			if (r){
				$.ajax({
				  url: "/interface.php",
				  async: true,
				  type:'POST',
				  dataType:'json',
				  data:{type:'img',id:id,action:'delete'},
				  success: function(msg){
					if (msg == 'success'){
						$.messager.alert('成功','删除成功');
						var row = $('#list').datagrid('getSelected');
						var index = $('#list').datagrid('getRowIndex', row);
						$('#list').datagrid('deleteRow',index);
						updategrid();
					}
				  }
				});
			}
		});
	}
	function cancelrow(index){
		$('#list').datagrid('cancelEdit', index);
	}
	</script>
</head>
<body>
	<noscript>
		<div style=" position:absolute; z-index:100000; height:2046px;top:0px;left:0px; width:100%; background:white; text-align:center;">
			<img src="./images/noscript.gif" alt='抱歉，请开启脚本支持！' />
		</div>
	</noscript>
	<table id="list"></table >
</body>
</html>